package com.mytest.offer;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class SolutionJZ52 {

    public static void main(String[] args) {
        SolutionJZ52 solutionJZ6 = new SolutionJZ52();
        ListNode listNode = new ListNode(1);
        ListNode listNode1 = new ListNode(2);
        ListNode listNode2 = new ListNode(3);

        listNode.next = listNode1;
        listNode1.next = listNode2;

        solutionJZ6.findFirstCommonNode(listNode,null);
    }

    public ListNode findFirstCommonNode(ListNode pHead1, ListNode pHead2) {
        ListNode l1 = pHead1, l2 = pHead2;
        while(l1.val != l2.val){
            l1 = (l1==null) ? pHead2 : l1.next;
            l2 = (l2==null) ? pHead1 : l2.next;
        }
        return l1;
    }
}
